package com.filter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.servlet.M;
import com.servlet.My;

import hyl.ext.base.MySession;
import hyl.ext.base.Response;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor1 implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
		//System.out.println("拦截2");
		MySession tk =My.getSession(req);	
    //连续几次错误 直接退出到登录页面
		
		if(tk.incError()) {
			//System.out.println("MyInterceptor1-t");
			System.out.println(M.URL_login);
			return true;
		}else
		{
			//System.out.println("MyInterceptor1-c");
			tk.msg.setCode(0,  M.MSG_阻拦);
			Response.forwardOrJson(req, res, M.URL_login,tk.msg);		
			return false;
		}

	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest req, HttpServletResponse res, Object handler, Exception ex)
			throws Exception {
	}

}
